package com.ruoyi.energy.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.TcCarInOut;
import com.ruoyi.energy.service.ITcCarInOutService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 车辆出入Controller
 *
 * @author cjie
 * @date 2021-07-29
 */
@Api(tags = " 车辆出入-已经废弃")
@RestController
@RequestMapping("/tcCarInOut")
public class TcCarInOutController extends BaseController {
    @Autowired
    private ITcCarInOutService tcCarInOutService;

    /**
     * 查询车辆出入列表
     */
    @ApiOperation(value="查询车辆出入列表", notes="查询车辆出入列表")
    @PreAuthorize(hasPermi = "energy:tcCarInOut:list")
    @GetMapping("/list")
    public TableDataInfo list(TcCarInOut tcCarInOut) {
        startPage();
        List<TcCarInOut> list = tcCarInOutService.selectTcCarInOutList(tcCarInOut);
        return getDataTable(list);
    }

    /**
     * 导出车辆出入列表
     */
    @ApiOperation(value="导出车辆出入列表", notes="导出车辆出入列表")
    @PreAuthorize(hasPermi = "energy:tcCarInOut:export")
    @Log(title = "车辆出入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcCarInOut tcCarInOut) throws IOException {
        List<TcCarInOut> list = tcCarInOutService.selectTcCarInOutList(tcCarInOut);
        ExcelUtil<TcCarInOut> util = new ExcelUtil<TcCarInOut>(TcCarInOut.class);
        util.exportExcel(response, list, "车辆出入数据");
    }
    /**
     * 获取车辆出入详细信息
     */
    @ApiOperation(value="获取车辆出入详细信息", notes="获取车辆出入详细信息")
    @PreAuthorize(hasPermi = "energy:tcCarInOut:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tcCarInOutService.selectTcCarInOutById(id));
    }

    /**
     * 新增车辆出入
     */
    @ApiOperation(value="新增车辆出入", notes="新增车辆出入")
    @PreAuthorize(hasPermi = "energy:tcCarInOut:add")
    @Log(title = "车辆出入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcCarInOut tcCarInOut) {
        return toAjax(tcCarInOutService.insertTcCarInOut(tcCarInOut));
    }

    /**
     * 修改车辆出入
     */
    @ApiOperation(value="修改车辆出入", notes="修改车辆出入")
    @PreAuthorize(hasPermi = "energy:tcCarInOut:edit")
    @Log(title = "车辆出入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcCarInOut tcCarInOut) {
        return toAjax(tcCarInOutService.updateTcCarInOut(tcCarInOut));
    }

    /**
     * 删除车辆出入
     */
    @ApiOperation(value="删除车辆出入", notes="删除车辆出入")
    @ApiImplicitParam(name = "ids", value = "车辆出入ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:tcCarInOut:remove")
    @Log(title = "车辆出入", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tcCarInOutService.deleteTcCarInOutByIds(ids));
    }
}
